define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
          // 初始化表格参数配置
          Table.api.init({
            extend: {
                    index_url: 'wadviser/config/index',
                    add_url: 'wadviser/config/add?adviser_id='+Config.adviser_id,
                    edit_url: 'wadviser/config/edit',
                    del_url: 'wadviser/config/del',
                    multi_url: 'wadviser/config/multi',
                    table: 'AdviserConfig',
                }
            });

            var table = $('#table');
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                queryParams: function (params) {
                    let filter = JSON.parse(params.filter); // 过滤字段
                    let op = JSON.parse(params.op); // 过滤条件
                    filter.adviser_id = Config.adviser_id;
                    op.adviser_id = '=';
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                },
                columns: [
                    [{
                        checkbox: true
                    },
                    {
                        field: 'id',
                        title: __('Id'),
                        operate: false
                    },
                    {
                        field: 'title',
                        title: __('标题'),
                    },
                    {
                        field: 'type',
                        title: __('类型'),
                        operate: false,
                        searchList: Config.typeList,
                        formatter: Table.api.formatter.label
                    },
                    {field: 'name', operate: false,title: __('变量名')},
                    {field: 'value', operate: false,title: __('默认值')},
                    {field: 'tip', operate: false,title: __('描述')},
                    {field: 'content', operate: false,title: __('选项内容')},
                    {field: 'weigh', title: __('Weigh'), operate: false},
                    {
                        field: 'operate',
                        title: __('Operate'),
                        table: table,
                        events: Table.api.events.operate,
                        formatter: Table.api.formatter.operate
                    }]
                ]
            });

            Table.api.bindevent(table);
        },
        add: function () {
            //切换显示隐藏变量字典列表
            $(document).on("change", "form#add-form select[name='row[type]']", function (e) {
                $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
            });
            Controller.api.bindevent();
        },
        edit: function () {
            //切换显示隐藏变量字典列表
            $(document).on("change", "select[name='row[type]']", function (e) {
                $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
            });
            $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($("select[name='row[type]']").val()) > -1 ? false : true);
            console.log($("select[name='row[type]']").val())
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($('form[role=form]'));
            }
        }
    };
    return Controller;
});